/**
 * @author chenxing
 */
public class code_283 {
    public static void moveZeroes(int[] nums) {
        int zeroIndex = 0;
        int notZeroIndex = 0;
        int arrLength = nums.length;
        while (notZeroIndex < arrLength && zeroIndex < arrLength) {
            //找到第一个0索引
            if (nums[zeroIndex] != 0) {
                zeroIndex++;
                continue;
            }
            //非0索引快速前进
            if (notZeroIndex < zeroIndex) {
                notZeroIndex = zeroIndex + 1;
            }
            //越界结束
            if (notZeroIndex == arrLength) {
                break;
            }
            //找到第一个非0索引
            if (nums[notZeroIndex] == 0) {
                notZeroIndex++;
                continue;
            }
            //交换
            nums[zeroIndex] = nums[notZeroIndex];
            nums[notZeroIndex] = 0;
        }
    }
}
